#include "netlib.h"
#include "riolib.h"
#include <stdio.h>

int main(int argc, char** argv)
{
	int clientfd, port;
	char *host, buf[MAXLINE];
	rio_t rio;

	if(argc != 3) {
		fprintf(stderr, "usage: %s <host> <port>\n", argv[0]);
		exit(0);
	}

	host = argv[1];
	port = atoi(argv[2]);
	clientfd = open_clientfd(host, port);
	rio_init(&rio, clientfd);

	printf("clientfd: %d\n", clientfd);
	while(fgets(buf, MAXLINE, stdin) != NULL) {
		rio_writen(clientfd, buf, strlen(buf));
		rio_readline(&rio, buf, MAXLINE);
		fputs(buf, stdout);
	}

	close(clientfd);
	return 0;
}
